import request from '@/utils/request';
import {
  ResumeReq,
  Res,
  putResumeFolderReq,
  getResumeReq,
  getResumeRes,
  uploadResumeReq,
  uploadResumeRes,
  checkResumeReq,
} from './types';
import { fetchReader } from '@/utils/requestQueue';
//新建文件夹
export const makeResumeFolder = (data: ResumeReq) => {
  return request.post<Res>({
    url: '/api/v1/resume/folder',
    data,
  });
};
//更新文件夹
export const putResumeFolder = (data: putResumeFolderReq) => {
  return request.put<Res>({
    url: '/api/v1/resume/folder',
    data,
  });
};
//获取文件夹简历列表
export const getResumeList = () => {
  return request.get<Res>({
    url: '/api/v1/resume/folder/list',
  });
};
//删除文件夹简历列表
export const deleteResumeList = (folderId: string) => {
  return request.delete<Res>({
    url: `/api/v1/resume/folder/${folderId}`,
  });
};
//获取简历
export const getResume = (data: getResumeReq) => {
  return request.get<getResumeRes>({
    url: `/api/v1/resume/list`,
    params: data,
  });
};
//上传简历
export const uploadResume = (data: uploadResumeReq) => {
  const formData = new FormData();
  formData.append('resume', data.file);
  formData.append('folder_id', data.folder_id);
  return request.post<uploadResumeRes>({
    url: '/api/v1/resume/upload',
    data: formData,
    headers: {
      pop: true,
    },
  });
};
//删除简历
export const deleteResume = (resumeId: number) => {
  return request.delete<Res>({
    url: `/api/v1/resume/delete/${resumeId}`,
  });
};
//筛选简历
// export const filterResume = (data: checkResumeReq) => {
//   return request.post<getResumeRes>({
//     url: `/api/v1/resume/check`,
//     data,
//   });
// };
export const filterResume = (data: checkResumeReq) => {
  return fetchReader('/api/v1/resume/check', {
    method: 'POST',
    body: JSON.stringify(data),
    headers: {
      'Content-Type': 'application/json',
      Authorization: localStorage.getItem('token') || '',
    },
  } as RequestInit);
};

//评估简历
// export const evaluateResume = (data) => {
//   return request.post<Res>({
//     url: `/api/v1/resume/evaluate`,
//     data,
//   });
// };
export const evaluateResume = (data) => {
  return fetchReader('/api/v1/resume/evaluate', {
    method: 'POST',
    body: JSON.stringify(data),
    headers: {
      'Content-Type': 'application/json',
      Authorization: localStorage.getItem('token') || '',
    },
  } as RequestInit);
};
